package org.dragonnova.meetingclient.core.net.netty;

import android.util.Log;

import org.dragonnova.meetingclient.core.message.Message;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * Created by hucn on 2016/5/19.
 * Description: 用于Netty的ChannelInitializer中，编码需要发送的TCP的包的内容
 */
public class MsgEncoder extends MessageToByteEncoder<Message> {

    private static final String TAG = MsgEncoder.class.getName();

    @Override
    protected void encode(ChannelHandlerContext ctx, Message msg, ByteBuf out)
            throws Exception {
        Log.i(TAG, "start encoding...");
        out.writeBytes(msg.encode());
    }
}
